#ifndef TCPSERVER_H
#define TCPSERVER_H

#ifdef _WIN32
	#include "winsock2.h"
	#pragma comment(lib,"ws2_32.lib")
#else
	#include <stdio.h>
	#include <string>
	#include <arpa/inet.h>
	#include <errno.h>
	#include <sys/types.h>
	#include <sys/socket.h>
	#include <unistd.h>
	#include <netinet/in.h>
	#include <netdb.h>
#endif
	#include <string>
	using namespace std;

class TCPServer
{
public:
	TCPServer();
	~TCPServer();

	bool setListenPort(int serPort);
	int setAccept(TCPServer *pSocket, struct sockaddr *clientAddr, int timeOut);
	int sendData(const char *szContent,int nLength,int nTimeOut=-1);
	int receiveAllData(char *bufRecv,int nTimeOut=-1);

	void initSocketfd(int socketfd);
	int  getSocketfd();
	void initm_bConnect(bool bConnect);
	int  getm_bConnect();
	void setIpAdd(char *tempIp);
	void setPort(int tempPort);
	char *socketIP();
	int  socketPort();
	void closeTcpSocket();

private:
	int receive(char *szBuf,int nBufLength,int nTimeOut=-1);
	int	 m_Socket;
	int	 m_nPort;
	bool m_bTcpInit;
	bool m_bConnect;
	char *m_pIpAddr;
};

#endif
